/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.sql.*;

/**
 *
 */
public class ObtenerTiempo {


  public ObtenerTiempo(){}//constructor

  public void Tiempo(){
    try {
        String driver = "org.gjt.mm.mysql.Driver";
        String url = "jdbc:mysql://localhost:3306/sudoku";
        String username = "root";
        String password = "gordo1513";
        // Abre el driver de la base de datos
        Class.forName(driver);
        // Establece la coneccion con la base de dato
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(" TABLAS DE LA BASE DE DATOS ");
        System.out.println();
        String query = "SELECT * FROM Tablero ";
        PreparedStatement statement = connection.prepareStatement(query);
        //      statement.setString(1, "2");
        ResultSet resultSet = statement.executeQuery();
        // Send query to database and store results.
        //Extrae de la base de datos el contenido de la tabla
        //para luego mostrarla por pantalla.
        while(resultSet.next()) {
          // Quarter
          System.out.println(" Tiempo: " + resultSet.getString(1));
	  System.out.print("\n   ");
        }
    }
    catch(ClassNotFoundException cnfe) {
      System.err.println("Error loading driver: " + cnfe);
    }
    catch(SQLException sqle) {
    	sqle.printStackTrace();
        System.err.println("Error connecting: " + sqle);
    }
  }
  
   

  public void getTopTen(){
    try {
        String driver = "org.gjt.mm.mysql.Driver";
        String url = "jdbc:mysql://localhost:3306/sudoku";
        String username = "root";
        String password = "gordo1513";
        // Abre el driver de la base de datos
        Class.forName(driver);
        // Establece la coneccion con la base de dato
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(" DIEZ MEJORES ");
        System.out.println();
        String query = "SELECT Tiempo FROM Tablero ORDER BY Tiempo ASC LIMIT 0,10";
        PreparedStatement statement = connection.prepareStatement(query);
        //      statement.setString(1, "2");
        ResultSet resultSet = statement.executeQuery();
        // Send query to database and store results.
        //Extrae de la base de datos el contenido de la tabla
        //para luego mostrarla por pantalla.
        while(resultSet.next()) {
          // Quarter
          System.out.println(" Topten: " + resultSet.getString(1));
	  System.out.print("\n   ");
        }
    }
    catch(ClassNotFoundException cnfe) {
      System.err.println("Error loading driver: " + cnfe);
    }
    catch(SQLException sqle) {
    	sqle.printStackTrace();
        System.err.println("Error connecting: " + sqle);
    }
  }
}
  